[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
for Signals the Start of a FOR Loop
for <index> := <start> to <finish> do
<statement>;
for <index> := <start> downto <finish> do
<statement>;
The FOR loop allows you to execute a statement some number of times.
An index variable is set to an initial ordinal value, <start>. If
<index>'s value is greater than the ending value, <finish>, then the
FOR loop is completed, and execution continues at the first statement
following the FOR loop; otherwise, <statement> is executed, <index> is
set to the next possible value, and the test is made again. If <start>
is greater than <finish>, then <statement> is never executed.
The DOWNTO keyword is used when you want a FOR loop to go from a high
value to a low value: <index> is decremented, and the loop ends when
<index>'s value is less than <finish>. If <start> is less than
<finish>, then <statement> is never executed.
<index> Any declared ordinal (Integer, Char, Boolean,
enumerated) variable.
<start>,<finish> Any expression of the same type as <index>.
<statement> Any legal statement; for multiple statements, use a
compound statement.
-------------------------------- Example ---------------------------------
for I := 0 to 10 do begin
J := I*I;
Writeln(I:2,J:4)
end;
for I := 1 to 100 do begin
Write('Enter next value: ');
Readln(List[I])
end;
for Power := -10 to 10 do
Writeln('e^',Power,' = ',Exp(Power):10);
for Flag := True downto False do
if Flag
then Writeln('It''s true, now')
else Writeln('Now it''s not');
See Also:
downto
to
begin
while
repeat
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson